package com.ztesoft.report.controller;


import com.ztesoft.report.base.controller.BaseController;
import com.ztesoft.report.entity.ReportUpload;
import com.ztesoft.report.service.ReportUploadService;
import com.ztesoft.report.utils.AESUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 谭宏伟
 * @since 2018-06-13
 */
@RestController
@RequestMapping("/reportUpload")
public class ReportUploadController extends BaseController{
    @Autowired
    ReportUploadService reportUploadService;

    @RequestMapping("/list")
    public Object list(@RequestBody Map<String, Object> map) {
        return reportUploadService.queryPage(map);
    }

    @RequestMapping("/removeRowData")
    public Object removeRowData(@RequestBody ReportUpload reportUpload) {
        return reportUploadService.deleteById(reportUpload);
    }

    @RequestMapping("/insertRowData")
    public Object insertRowData(@RequestBody ReportUpload reportUpload) {
        //取消前台传入的id值
        reportUpload.setId(null);
        reportUpload.setPassword(AESUtil.encrypt(reportUpload.getPassword()));
        return reportUploadService.insert(reportUpload);
    }

    @RequestMapping("/updateRowData")
    public Object updateRowData(@RequestBody ReportUpload reportUpload) {
        reportUpload.setPassword(AESUtil.encrypt(reportUpload.getPassword()));
        return reportUploadService.updateById(reportUpload);
    }
}
